package huzh.tag;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.DynamicAttributes;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *<p>title:DynamicTag</p>
 *<p>description:</p>
 * @since 2014-6-16
 * @author huzh
 * @version 1.0
 */
public class DynamicTag extends SimpleTagSupport implements DynamicAttributes{

    /**keys*/
    private ArrayList<String> keys = new ArrayList<String>();
    /**values*/
    private ArrayList<String> values = new ArrayList<String>();
    
    /**
     * @param uri
     * @param key
     * @param value
     * @throws JspException
     */
    @Override
    public void setDynamicAttribute(String uri, String key, Object value)
            throws JspException {
        keys.add(key);
        values.add(String.valueOf(value));
    }

    @Override
    public void doTag() throws JspException, IOException {
        // TODO Auto-generated method stub
        JspWriter out = getJspContext().getOut();
        out.println("<ol>");
        for(int i=0;i<keys.size();i++){
            out.println("<li>"+keys.get(i)+" = " +values.get(i)+"</li>");
        }
        out.println("</ol>");
    }

}
